package com.jianguozh.difs.support.service.constant.enums;

import cn.hutool.core.util.ArrayUtil;
import com.baomidou.mybatisplus.annotation.IEnum;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import com.jianguozh.difs.framework.annotation.EnumDesc;
import com.jianguozh.difs.support.service.component.file.core.client.FileClientSetting;
import com.jianguozh.difs.support.service.component.setting.Setting;
import com.jianguozh.difs.support.service.event.FileClientConfigSucceedEvent;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.context.ApplicationEvent;

/**
 * 配置类型枚举
 *
 * @author hanrs
 * @email 4076130@qq.com
 * @since 2022/7/5 13:42
 */
@AllArgsConstructor
@Getter
@EnumDesc(title = "配置项")
public enum ConfigTypeEnum implements IEnum<String> {

    FILE_CLIENT_CONFIG("FILE-CLIENT-CONFIG", "文件存储器客户端", FileClientSetting.class, FileClientConfigSucceedEvent.class),
    ;

    /**
     * 存储器
     */
    @JsonValue
    private final String value;

    /**
     * 存储器名称
     */
    private final String displayName;

    /**
     * 配置类
     */
    private final Class<? extends Setting> settingClass;

    /**
     * 配置修改成功通知事件
     */
    private final Class<? extends ApplicationEvent> eventClass;

    @JsonCreator
    public static ConfigTypeEnum fromValue(String value) {
        return ArrayUtil.firstMatch(o -> o.getValue().equals(value), values());
    }

}
